package com.commerce.product.config;

import com.commerce.product.interceptor.AntiSpamInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web配置类
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private AntiSpamInterceptor antiSpamInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(antiSpamInterceptor)
                .addPathPatterns("/api/flash-sale/purchase")  // 只拦截秒杀购买接口
                .excludePathPatterns(
                    "/api/flash-sale/list",              // 排除商品列表查询
                    "/api/flash-sale/current",          // 排除当前活动查询
                    "/api/flash-sale/products/**",      // 排除商品详情查询
                    "/api/flash-sale/stock/**",         // 排除库存查询
                    "/api/flash-sale/check/**",         // 排除资格检查
                    "/api/flash-sale/admin/**"          // 排除管理员接口
                );
    }
}
